package com.jy.filter;


import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/*
 * 登陆检查过滤器
 */
//@WebFilter("/login/*")
//@WebFilter("*.jsp")
@WebFilter({"/html/*","/stu/*"})
public class Filter1_LoginFilter implements Filter {

	public void destroy() {
		System.out.println("LoginFilter 销毁");
	}
	//doFilter(1、请求,2、响应,3、过滤器链)
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		HttpServletRequest req=(HttpServletRequest)request;
		HttpServletResponse res=(HttpServletResponse)response;
		String uri=req.getRequestURI();//访问路径
		System.out.println("访问路径:"+uri);
		System.out.println("LoginFilter 正在过滤....");
		Object act=req.getSession().getAttribute("act");
		System.out.println(act);
		if(act==null){
			res.sendRedirect("/examproject/nologin/LogInTo.jsp");
			return;
		}else{
			chain.doFilter(request, response);
		}

	}

	public void init(FilterConfig fConfig) throws ServletException {
			System.out.println("LoginFilter 初始化");
	}

}
